package com.new2i.action;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.new2i.aop.LoginInterceptor;
import com.new2i.model.DoctorEntity;
import com.new2i.model.ScreenDoctorEntity;
import com.new2i.service.able.ScreenDoctorService;
import com.new2i.util.Collection2JsonUtil;

/**
 * 通行证相应接口
 * 
 * @since 2015/09/04
 * @author 2i
 *
 */
@Controller
@RequestMapping("api/doctor")
public class DoctorApiAction extends BaseAction {

	@Autowired
	private transient ScreenDoctorService mScreenDoctorService;

	/**
	 * 创建筛查医生
	 * 
	 * @author 2i
	 * @since 2015/09/22
	 * @param request
	 * @param response
	 * @param scDoctor
	 */
	@LoginInterceptor
	@RequestMapping("/create.action")
	public void createScreenDoctor(HttpServletRequest request, HttpServletResponse response,DoctorEntity doctor,
			ScreenDoctorEntity scDoctor) {
		scDoctor.setDoctor_id(doctor.getDoctor_id());
		HashMap<String, Object> map = mScreenDoctorService.insertScreenDoctor(scDoctor);
		String value = Collection2JsonUtil.byObject(map);
		write2client(response, value);
	}
	
	/**
	 * 创建筛查医生
	 * 
	 * @author 2i
	 * @since 2015/09/22
	 * @param request
	 * @param response
	 * @param scDoctor
	 */
	@RequestMapping("/list.action")
	public void selectScreenDoctorList(HttpServletRequest request, HttpServletResponse response,DoctorEntity doctor,
			ScreenDoctorEntity scDoctor) {
		List<HashMap<String, Object>> list = mScreenDoctorService.selectScreenDoctorList(doctor);
		String value = Collection2JsonUtil.byList(list, "sc_doctor_list");
		write2client(response, value);
	}
	
	/**
	 * 修改筛查医生的登录密码
	 * 
	 * @author 2i
	 * @since 2015/09/23
	 * @param request
	 * @param response
	 * @param doctor
	 * @param scDoctor
	 */
	@RequestMapping("/pwd/update.action")
	public void updateScreenDoctorPassword(HttpServletRequest request, HttpServletResponse response,DoctorEntity doctor,
			ScreenDoctorEntity scDoctor) {
		HashMap<String, Object> map = mScreenDoctorService.updateScreenDoctorPassword(scDoctor);
		String value = Collection2JsonUtil.byObject(map);
		write2client(response, value);
	}
	
	
	/**
	 * 删除筛查医生账号
	 * 
	 * @author 2i
	 * @since 2015/09/23
	 * @param request
	 * @param response
	 * @param doctor
	 * @param scDoctor
	 */
	@RequestMapping("/delete.action")
	public void deleteScreenDoctor(HttpServletRequest request, HttpServletResponse response,DoctorEntity doctor,
			ScreenDoctorEntity scDoctor) {
		scDoctor.setDoctor_id(doctor.getDoctor_id());
		HashMap<String, Object> map = mScreenDoctorService.deleteScreenDoctor(scDoctor);
		String value = Collection2JsonUtil.byObject(map);
		write2client(response, value);
	}
}
